package com.lrabbit.mybatisplus.generator.util;

import com.baomidou.mybatisplus.generator.config.FileOutConfig;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.lrabbit.mybatisplus.generator.bean.GenConfig;

import java.util.ArrayList;
import java.util.List;

public class TempBootUtil {
    public static List<FileOutConfig> initBootTemp(String outputDir, GenConfig genConfig) {

        /************************ 【设置】xml 输入输出 ************************/

        List<FileOutConfig> fileOutConfigList = new ArrayList<>();

        fileOutConfigList.add(new FileOutConfig("/templates/mapper.xml.vm") {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 设置目录
                String xmlName = tableInfo.getXmlName();
                String xmlPath = outputDir.substring(0, outputDir.indexOf("java"));
                // 获取模块的名称 resources/mapper/${moduleName}
                String packageParentName = genConfig.getPackageParentName();
                String modelPath = xmlPath + "/resources/mapper/" + packageParentName.substring(packageParentName.lastIndexOf(".") + 1);
                return modelPath + "/" + xmlName + ".xml";
            }
        });
        return fileOutConfigList;
    }
}
